package com.assessment.web;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Predicate;
import javax.persistence.criteria.Root;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.assessment.dto.AssessmentTemplateDTO;
import com.assessment.entity.AssessmentTemplate;
import com.assessment.service.IAssessmentTemplateService;
import com.common.util.AJAXResultMessage;
import com.common.util.ExtjsPageable;
import com.syslog.aop.SystemServiceLog;
import com.system.entity.Role;



@Controller
@RequestMapping(value="/assessmentTemplate")
public class AssessmentTemplateController 
{
	@Autowired
	private IAssessmentTemplateService assessmentTemplateService;
	
	@SystemServiceLog("新建或修改考核模板基本属性")
	@RequestMapping(value="/saveOrUpdate")
	public @ResponseBody AJAXResultMessage saveOrUpdate(AssessmentTemplate assessmentTemplate) 
	{
		try {
			assessmentTemplateService.saveOrUpdate(assessmentTemplate);
    		return new AJAXResultMessage(true,"操作成功!");
	    } catch (Exception e) {
	    	e.printStackTrace();
	        return new AJAXResultMessage(false,"操作失败!");
	    }
	}
	
	@SystemServiceLog("删除考核模板")
	@RequestMapping(value = "/deleteTemplates")
    public @ResponseBody AJAXResultMessage delete(Long[] ids) {
    	try {
    		List<Long> idlists=Arrays.asList(ids);
    		if(null!=idlists) {
    			assessmentTemplateService.delete(idlists);
    		}    		
    		return new AJAXResultMessage(true,"操作成功!");
	    } catch (Exception e) {
	    	e.printStackTrace();
	        return new AJAXResultMessage(false,"操作失败!");
	    }
    }
	@SystemServiceLog("批量删除考核模板")
	@RequestMapping(value = "/delete")
    public @ResponseBody AJAXResultMessage delete(Long id) {
    	try {
    		assessmentTemplateService.delete(id);
    		return new AJAXResultMessage(true,"操作成功!");
	    } catch (Exception e) {
	    	e.printStackTrace();
	        return new AJAXResultMessage(false,"操作失败!");
	    }
    }
//	@RequestMapping("/findOne")
//	public @ResponseBody AssessmentTemplateDTO findOne(Long id) {
//		return assessmentTemplateService.findOne(id);
//	}
	
	@SystemServiceLog("查询考核模板")
	@RequestMapping("/findAll")
	public @ResponseBody Page<AssessmentTemplateDTO> findAll(AssessmentTemplateDTO assessmentTemplateDTO,ExtjsPageable pageable) 
	{
		Page<AssessmentTemplateDTO> page = new PageImpl<AssessmentTemplateDTO>(new ArrayList<AssessmentTemplateDTO>(), pageable.getPageable(), 0);

		page =assessmentTemplateService.findAll(AssessmentTemplateDTO.getSpecification(assessmentTemplateDTO), pageable.getPageable());		
		return page;
	}
	
}
